package com.ymatou.iapi.sellerquery.testcase;


import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerquery.parameter.GetRelatedOrderInfosBean;
import com.ymatou.iapi.sellerquery.parameter.resp.CreditInfoListResp;
import com.ymatou.iapi.sellerquery.parameter.resp.OrderInfoListResp;
import com.ymatou.iapi.sellerquery.parameter.resp.OrderItemInfoListResp;
import com.ymatou.iapi.sellerquery.service.GetRelatedOrderInfosCall;
import com.ymatou.paymentproxy.parameter.AcquireOrderBean;
import com.ymatou.query.seller.trading.api.parameter.ExportSellerOrderInfosResponse;
import com.ymatou.query.seller.trading.api.parameter.GetBlackBuyerListResponse;
import com.ymatou.query.trading.api.parameter.GetLatestPaidOrdersResponse;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.PaymentDefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;


	/**
	 * 获取相关订单详情Call FreeMaker Template自动生成代码
	 */
	@TestSuite
	public class Ts_GetRelatedOrderInfos {

		private static GetRelatedOrderInfosBean groisBean;
		private static GetRelatedOrderInfosCall groisCall;

		@BeforeClass
		public static void setUp() {
			Logger.createResultFile("获取相关订单详情");
		}

		@Before
		public void caseUp() {

			groisBean = new GetRelatedOrderInfosBean();
			groisCall = new GetRelatedOrderInfosCall();
		}

		@AfterClass
		public static void tearDown() {
			Logger.generateResult(groisCall.getOpurl());
		}

		@After
		public void caseDown() {
			Logger.end();
		}
		

		private void verifyDB() {
			int orderId = 112463948;
			Logger.comment("验证表ymt_orders");
			Map database = new DefaultWapper().selectOrderByOderId(orderId).get(0);
			Map database2 = new DefaultWapper().selectOrderInfoByOderId(orderId).get(0);
			ArrayList<OrderInfoListResp> list = groisCall.getResult();
			for (OrderInfoListResp returnMessage : list) {	
			Logger.verifyEquals( database.get("iOrderId"), 
					returnMessage.getOrderId(), "验证接口返回数据orderId");
			Logger.verifyEquals( database.get("iTradingStatus"), 
					returnMessage.getTradingStatus(), "验证接口返回数据tradingStatus");
			Logger.verifyEquals( database.get("iUserId"), 
					returnMessage.getUserId(), "验证接口返回数据userId");
			Logger.verifyEquals( database.get("sBuyerLoginId"), 
					returnMessage.getBuyerLoginId(), "验证接口返回数据buyerLoginId");
			Logger.verifyEquals( database.get("sSellerLoginId"), 
					returnMessage.getSellerLoginId(), "验证接口返回数据sellerLoginId");
			DecimalFormat df = new DecimalFormat("0.00");
			Logger.verifyEquals( database.get("fTotalPrice").toString(), 
					df.format(returnMessage.getPayableAmount()), "验证接口返回数据payableAmount");
			Logger.verifyEquals( database.get("sYmtCouponCode"), 
					returnMessage.getYmtCouponCode(), "验证接口返回数据ymtCouponCode");
			Logger.verifyEquals(df.format(database.get("fYmtCouponAmount")), 
					df.format(returnMessage.getYmtCouponAmount()), "验证接口返回数据ymtCouponAmount");
			Logger.verifyEquals( database.get("iMainOrderId"), 
					returnMessage.getMainOrderId(), "验证接口返回数据mainOrderId");
			
//			Logger.verifyEquals( database.get("fSellerpromotionAmount"), 
//					returnMessage.getPromotionReducedAmount(), "验证接口返回数据promotionReducedAmount");

			
			Logger.verifyEquals( database2.get("sTitle"), 
					returnMessage.getOrderItemInfoList().get(0).getTitle(), "验证接口返回数据title");
			Logger.verifyEquals( database2.get("sProductId"), 
					returnMessage.getOrderItemInfoList().get(0).getProductId(), "验证接口返回数据productId");
			Logger.verifyEquals( database2.get("sCatalogId"), 
					returnMessage.getOrderItemInfoList().get(0).getCatalogId(), "验证接口返回数据catalogId");
			Logger.verifyEquals( database2.get("iAmount"), 
					returnMessage.getOrderItemInfoList().get(0).getAmount(), "验证接口返回数据amount");
			
			Logger.verifyEquals( database2.get("fProductPrice").toString(), 
					df.format(returnMessage.getOrderItemInfoList().get(0).getProductPrice()), "验证接口返回数据productPrice");
			Logger.verifyEquals( database2.get("fSellerCouponAmount").toString(), 
					df.format(returnMessage.getOrderItemInfoList().get(0).getSellerCouponAmount()), "验证接口返回数据sellerCouponAmount");
			Logger.verifyEquals( database2.get("fYmtCouponAmount").toString(), 
					df.format(returnMessage.getOrderItemInfoList().get(0).getYmtCouponAmount()), "验证接口返回数据ymtCouponAmount");
			Logger.verifyEquals( database2.get("fDiscount").toString(), 
					df.format(returnMessage.getOrderItemInfoList().get(0).getDiscount()), "验证接口返回数据discount");
			Logger.verifyEquals( database2.get("fFreight").toString(), 
					df.format(returnMessage.getOrderItemInfoList().get(0).getFreight()), "验证接口返回数据freight");
			Logger.verifyEquals( database2.get("bSupportRtnWithoutReason"), 
					returnMessage.getOrderItemInfoList().get(0).getSupportRtnWithoutReason(), "验证接口返回数据supportRtnWithoutReason");
			
			}
		}

		@Test
		@Category(P1.class)
		@TestCase
		public void Tc_GetRelatedOrderInfos_001() {
			Logger.start(true,"根据OrderId获取相关订单详情,成功");
			try {
				int orderId = 112463948;
				groisBean.setOrderId(orderId);
				String s=FormatUtil.beanToHttpString(groisBean, true, false);			
				groisCall.setData(s);
				groisCall.callService();
				Logger.verifyEquals(ECode.SUCCESS, groisCall.getCode(), "验证Code");
				
				//数据库验证
				ArrayList<OrderInfoListResp> list = groisCall.getResult();
							
				DefaultWapper database = new DefaultWapper();	
				verifyDB();			
				
			} catch (Exception e) {
				Logger.fail(e);
			}
		}
		
		@Test
		@Category(P3.class)
		@TestCase
		public void Tc_GetRelatedOrderInfos_002() {
			Logger.start(false,"OrderId为空，获取相关订单详情,失败");
			try {
                //  int orderId = 112463948;
				//	groisBean.setOrderId(orderId);
					String s=FormatUtil.beanToHttpString(groisBean, true, false);			
					groisCall.setData(s);
					groisCall.callService();
					Logger.verifyEquals(ECode.SUCCESS, groisCall.getCode(), "验证Code");
			} catch (Exception e) {
				Logger.fail(e);
			}
		}
		
		@Test
		@Category(P1.class)
		@TestCase
		public void Tc_GetRelatedOrderInfos_003() {
			Logger.start(false,"OrderId不存在，获取相关订单详情为空,成功");
			try {
                    int orderId = 123456789;
					groisBean.setOrderId(orderId);
					String s=FormatUtil.beanToHttpString(groisBean, true, false);			
					groisCall.setData(s);
					groisCall.callService();
					Logger.verifyEquals(ECode.SUCCESS, groisCall.getCode(), "验证Code");
			} catch (Exception e) {
				Logger.fail(e);
			}
		}
}


